<template>
	<view class="container">
		<view class="form">
			<text class="title">登录</text>
			<input class="input" placeholder="请输入用户名" v-model="username"/>
			<input class="input" placeholder="请输入密码" password v-model="password" 
				:focus="isPwdfocus" 		
				@blur="isPwdfocus = false"
			 />
			  <!-- 动态绑定焦点状态 :focus="isPwdFocused"-->
			  <!-- 失去焦点时更新状态 @blur="isPwdFocused = false"-->
			<button class="btn" type="primary" @click="handleLogin">登录</button>
			<view class="link">
				<text>没有账号？</text>
				<navigator url="/pages/Register/Register">去注册</navigator>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				username: 'lfj',
				password: '123456',
				isPwdfocus:true
			}
		},
		methods: {
			handleLogin() {
				if (!this.username || !this.password) {
					uni.showToast({
						title: '请输入完整信息',
						icon: 'none'
					})
					return
				}
				if(this.username==='lfj'&& this.password==='123456'){
					uni.showLoading({
						title: '登录中...'
					})
					setTimeout(() => {
						uni.hideLoading()
						uni.showToast({
							title: '登录成功'
						})
						// 实际项目中这里跳转到首页
						uni.switchTab({
							url:"/pages/tabBar/tabcompage/tabcompage"
						})
					}, 1000)
				}else{
					uni.showToast({
						title: '密码错误，请重新输入'
					});
					this.password='';
					this.isPwdfocus=true;
				}
			}
		}
	}
</script>

<style>
	.container {
		display: flex;
		justify-content: center;
		align-items: center;
		height: 100vh;
		background-color: #f9f9f9;
	}

	.form {
		width: 80%;
		padding: 40rpx;
		background: #fff;
		border-radius: 16rpx;
		box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.1);
	}

	.title {
		font-size: 40rpx;
		text-align: center;
		margin-bottom: 40rpx;
		display: block;
	}

	.input {
		border: 1px solid #ddd;
		border-radius: 8rpx;
		padding: 20rpx;
		margin-bottom: 30rpx;
	}

	.btn {
		margin-top: 20rpx;
	}

	.link {
		margin-top: 30rpx;
		text-align: center;
		font-size: 28rpx;
		color: #666;
	}

	.link navigator {
		display: inline;
		color: #007AFF;
	}
</style>